package com.bytenebula.asteroid.service.impl;

import com.bytenebula.asteroid.entity.dto.MetaDatabaseDTO;
import com.bytenebula.asteroid.entity.vo.MetaDatabaseVO;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.bytenebula.asteroid.entity.MetaDatabase;
import com.bytenebula.asteroid.mapper.MetaDatabaseMapper;
import com.bytenebula.asteroid.service.MetaDatabaseService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *  服务层实现。
 *
 * @author patrick
 * @since 2024-09-15
 */
@Service
public class MetaDatabaseServiceImpl extends ServiceImpl<MetaDatabaseMapper, MetaDatabase> implements MetaDatabaseService {

    /**
     * 根据数据库名称查询
     * @param name 数据库名称
     * @return 返回数据源元数据
     */
    @Override
    public MetaDatabase getByName(String name) {
        return this.getOne(QueryWrapper.create().eq("db_name", name));
    }

    /**
     * 获取数据库列表，包含内部子对象
     *
     * @return 返回数据库对象列表
     */
    @Override
    public List<MetaDatabaseDTO> listWithRelation() {
         return mapper.selectListWithRelationsByQueryAs(QueryWrapper.create(), MetaDatabaseDTO.class);
    }
}
